package main.java.utils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Base64;
import java.util.Base64.Encoder;

public class DownloadUtils {
    public static String getFileName(String agent, String filename) throws UnsupportedEncodingException {
        if(agent.contains("MSIE")){
            filename = URLEncoder.encode(filename, "utf-8");
            filename = filename.replace("+", " ");
        }else if(agent.contains("Firefox")){
            Encoder encoder =  Base64.getEncoder();
            filename = "=?utf-8?B?"+encoder.encode(filename.getBytes("utf-8"))+"?=";
        }else{
            filename = URLEncoder.encode(filename, "utf-8");
        }
        return filename;
    }
}
